
/**
 * <p>Title: Judging Tool</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author Sujal Bista
 * @version 1.0
 */
/*
 * judge.java
 *
 * Created on January 8, 2006, 9:40 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

/**
 *
 * @author Sujal Bista
 */
import java.sql.Timestamp;
import java.util.*;
import java.io.*;

public class judge
{
    //Catagorizes judges by type
    enum judgeType{ judgeA, judgeB, judgeC};

    //data structure for judge
    public class dataChunk
    {
        //to record time stamp
        public java.sql.Timestamp time;
        public String value;

        //default constructor
        public dataChunk()
        {

        }

        public dataChunk(dataChunk data)
        {
            time=data.time;
            value=data.value;
        }

        //constructor
        public dataChunk(java.sql.Timestamp time,String value)
        {
            this.time=time;
            this.value=value;
        }

        //converts to string
        public String toString()
        {
            String st=new String();
            st=time.toString();
            st+=" = "+ value;
            return new String(time.toString()+" = "+ value);
        }

        //reads the value off the string
        public  void valueOf(String str)
        {
            int index=str.indexOf('=');
            String timeStamp=str.substring(0, index);
            String value=str.substring(index+2);

            time=time.valueOf(timeStamp);
            this.value=value;
        }
    }

    //Type of judge
    public judgeType defaultType;
    public judgeType type;

    //Judges initial or signature;
    private String sign;

    //name of the current athlete
    private String currentAthlete;

    private ArrayList<dataChunk> dataList;

    //private PrintWriter outFile;

    /** Creates a new instance of judge */
    public judge(judgeType jType,String signature)
    {
        defaultType=type=jType;
        sign=signature;
        dataList = new ArrayList<dataChunk>();

    }

    public void beginAthlete(String athleteData)
    {
        //currently the athlete data is just name
        currentAthlete=athleteData;
        String fileName=currentAthlete+" "+System.currentTimeMillis()+".txt";
        //try
        //{
        //    outFile=new PrintWriter(new FileOutputStream(fileName));
        //}
        //catch(FileNotFoundException e)
        //{
        //      System.out.println("Error : File \""+fileName+"\" cannot be opened. ");
        //}
    }

    public void updateAthelete(String value)
    {
        dataChunk data=new dataChunk(new java.sql.Timestamp(System.currentTimeMillis()),value);
        dataList.add(data);
        //outFile.println(data.toString());
        //outFile.flush();
    }
    
    public void setType(judgeType jType)
    {
        type=jType;
    }

    public void endAthlete()
    {
        if (dataList != null)
            dataList.clear();
        //if (outFile != null)
         //   outFile.close();
    }

}
